﻿@inject NavigationManager Nav;
@inject IJSRuntime JS;

<div class="doc-menu">
    <div class="menus">
        @foreach (var menu in Menus)
        {
            <div class="title">@menu.Name</div>
            <ul>
                @foreach (var item in menu.Children)
                {
                    var cls = CurItem == item.Id ? "active" : "";
                    <li class="@cls" @onclick="@(e => OnMenuItemClick(item))">@item.Name</li>
                }
            </ul>
        }
    </div>
</div>

@code {
    private List<MenuItem> Menus = DocService.GetDocMenus();

    [Parameter] public string? CurItem { get; set; }

    private async void OnMenuItemClick(MenuItem item)
    {
        CurItem = item.Id;
        Nav.NavigateTo($"/doc/{item.Id}");
        await JS.InvokeVoidAsync("hideDocNav");
    }
}